package com.ruoyi.web.controller.warning;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.warning.WarningConfig;
import com.ruoyi.web.domain.warning.WarningInsect;
import com.ruoyi.web.pojo.request.warning.WarningConfigRequest;
import com.ruoyi.web.pojo.request.warning.WarningInsectRequest;
import com.ruoyi.web.service.warning.WarningInsectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "昆虫识别预警",tags = "昆虫识别预警")
@RestController
@RequestMapping("/warning-insect")
public class WarningInsectController extends BaseController {

    @Autowired
    private WarningInsectService warningInsectService;

    @ApiOperation("分页获取昆虫识别预警")
    @GetMapping("/queryPage")
    public TableDataInfo<WarningInsect> queryPage(WarningInsectRequest request){
        startPage();
        List<WarningInsect> insects = warningInsectService.queryPage(request);
        return getDataTable(insects);
    }

    @PostMapping("/updateEnable")
    @ApiImplicitParams({  @ApiImplicitParam(name = "configId",value = "昆虫配置id", required = true) ,
            @ApiImplicitParam(name = "flag",value = "0 启用 1 停用", required = true)})
    @ApiOperation("启用或停用虫情预警配置")
    public R<Map> updateEnable(@RequestParam Integer configId, @RequestParam Integer flag) {
        warningInsectService.updateEnable(configId,flag);
        return R.ok();
    }

    @PostMapping("/updateWarningInsect")
    @ApiOperation("新增或修改虫情预警配置")
    public R<Map> updateWarningInsect(@RequestBody WarningInsect config) {
        warningInsectService.saveOrUpdateInfo(config);
        return R.ok();
    }
}
